package leetcode_401_500;

import node.TreeNode;

public class LeeCode_450 {
    public static void main(String[] args) {

    }
    private static TreeNode deleteNode(TreeNode root, int key) {
        if (root == null){
            return null;
        }
        if (root.val < key){
            root.right = deleteNode(root.right, key);
            return root;
        }
        if (root.val > key){
            root.left = deleteNode(root.left, key);
            return root;
        }
        if (root.left == null && root.right == null){
            return null;
        }
        if (root.left == null){
            return root.right;
        }
        if (root.right == null){
            return root.left;
        }
        TreeNode su = root.right;
        while (su.left != null){
            su = su.left;
        }
        root.right = deleteNode(root.right, su.val);
        su.left = root.left;
        su.right = root.right;
        return su;
    }
}
